"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    // argsnum 参数个数
    var argsnum = arguments.length
    // targetinfo 被装饰器修饰的目标
    // argsnum=2 装饰器修饰的是类或者构造器参数，targetinof=target[类名]
    // argsnum=4 装饰器修饰的是方法【第四个参数desc等于null】targetinfo=该方法的数据属性【desc = Object.getOwnPropertyDescriptor(target, key)】
    // argsnum=3 装饰器修饰的是方法参数或属性，targetinfo=undefined
    var targetinfo = argsnum < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;  // s100
    // decorator保存装饰器数组元素
    var decorator;
    // 元数据信息，支持reflect-metadata元数据
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
      targetinfo = Reflect.decorate(decorators, target, key, desc);
    } else {
      // 装饰器循环，倒着循环，说明同一个目标上有多个装饰器，执行循环是倒着执行
      for (var i = decorators.length -1; i >=0; i--) {
        // 如果参数小于3【decorator为类装饰器或者构造器参数装饰器】执行decorator(targetinof)直接执行decorator装饰器，并传递目标targetinfo，这里是类
        //如果参数大于3【decorator为方法装饰器】 直接执行 decorator(target, key, targetinfo)
     //如果参数等于3【decorator为方法参数装饰器或者属性装饰器】，直接执行decorator(target,key)
     //targetinfo最终为各个装饰器执行后的返回值，但如果没有返回值，直接返回第s100行的targetinfo
        targetinfo = (argsnum < 3 ? decorator(targetinfo) : argsnum > 3 ?
            decorator(target, key, targetinfo) : decorator(target, key)) || targetinfo;
        console.log("targetinforesult:", targetinfo)
      }
    }
    return argsnum > 3 && targetinfo && Object.defineProperty(target, key, targetinfo), targetinfo;
}
Object.defineProperty(exports, "__esModule", { value: true });
// 不带参数的类装饰器
// targetClass 就是 Customer类构造函数 本身
function FirstClassDecorator(targetClass) {
    var targetClassObj = new targetClass("张三");
    targetClassObj.buy();
    console.log(targetClass.name);
}
var Customer = /** @class */ (function () {
    function Customer(name) { this.name = name; };
    Customer.prototype.sayName = function () { console.log("我是, ", this.name); };;
    Customer.prototype.buy = function () { console.log("".concat(this.name, "\uFF0C\u5DF2\u7ECF\u4E0B\u5355\u4E86")); };;
    Customer = __decorate([
        FirstClassDecorator
    ], Customer);
    return Customer;
}());
// 带参数的类装饰器
function HasParamClassDecorator(param) {
    console.log("param: ", param);
    return function (targetClass) {
        var targetClassObj = new targetClass("李四");
        targetClassObj.buy();
        console.log(targetClass.name);
    };
}
var Customer2 = /** @class */ (function () {
    function Customer2(name) { this.name = name };
    Customer2.prototype.sayName = function () { console.log("我是, ", this.name); };;
    Customer2.prototype.buy = function () { console.log("".concat(this.name, "\uFF0C\u5DF2\u7ECF\u4E0B\u5355\u4E86")); };;
    Customer2 = __decorate([
        HasParamClassDecorator('hello')
    ], Customer2);
    return Customer2;
}());
